/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.raflik.queryxml.ui.model;

import org.netbeans.swing.outline.RowModel;
import org.openide.util.NbBundle;
import org.w3c.dom.Node;
import pl.raflik.queryxml.lib.XMLNodePresenter;

/**
 *
 * @author raflik
 */
public class ResultRowModel implements RowModel {
    public enum Columns {
        Type,
        Name,
        Value;

        public String toText() {
            return NbBundle.getMessage(ResultRowModel.Columns.class, "ResultNode.Columns." + this);
        }
    }

    public ResultRowModel() {
    }

    public int getColumnCount() {
        return Columns.values().length - 1;
    }

    public Object getValueFor(Object obj, int index) {
        switch (index) {
            case 0:
                if (obj instanceof Node) {
                    Node node = (Node) obj;
                    return XMLNodePresenter.getNodeName(node);
                }
                return obj.getClass().getCanonicalName();
            case 1:
                if (obj instanceof Node) {
                    Node node = (Node) obj;
                    return XMLNodePresenter.getNodeValue(node);
                }
                return obj;
            default:
                assert false;
        }
        return null;
    }

    public Class getColumnClass(int arg0) {
        return String.class;
    }

    public boolean isCellEditable(Object arg0, int arg1) {
        return false;
    }

    public void setValueFor(Object arg0, int arg1, Object arg2) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getColumnName(int arg0) {
        return Columns.values()[arg0 + 1].toText();
    }

}
